package com.blog.web.controller.blog;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.blog.common.annotation.Log;
import com.blog.common.core.controller.BaseController;
import com.blog.common.core.domain.AjaxResult;
import com.blog.common.enums.BusinessType;
import com.blog.system.domain.blog.BlogTags;
import com.blog.system.service.blog.IBlogTagsService;
import com.blog.common.utils.poi.ExcelUtil;
import com.blog.common.core.page.TableDataInfo;

/**
 * 文章标签Controller
 * 
 * @author shibalover
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/blog/tags")
public class BlogTagsController extends BaseController
{
    @Autowired
    private IBlogTagsService blogTagsService;

    /**
     * 查询文章标签列表
     */
    @PreAuthorize("@ss.hasPermi('blog:tags:list')")
    @GetMapping("/list")
    public TableDataInfo list(BlogTags blogTags)
    {
        startPage();
        List<BlogTags> list = blogTagsService.selectBlogTagsList(blogTags);
        return getDataTable(list);
    }

    /**
     * 导出文章标签列表
     */
    @PreAuthorize("@ss.hasPermi('blog:tags:export')")
    @Log(title = "文章标签", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogTags blogTags)
    {
        List<BlogTags> list = blogTagsService.selectBlogTagsList(blogTags);
        ExcelUtil<BlogTags> util = new ExcelUtil<BlogTags>(BlogTags.class);
        util.exportExcel(response, list, "文章标签数据");
    }

    /**
     * 获取文章标签详细信息
     */
    @PreAuthorize("@ss.hasPermi('blog:tags:query')")
    @GetMapping(value = "/{tagsId}")
    public AjaxResult getInfo(@PathVariable("tagsId") Long tagsId)
    {
        return success(blogTagsService.selectBlogTagsByTagsId(tagsId));
    }

    /**
     * 新增文章标签
     */
    @PreAuthorize("@ss.hasPermi('blog:tags:add')")
    @Log(title = "文章标签", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogTags blogTags)
    {
        return toAjax(blogTagsService.insertBlogTags(blogTags));
    }

    /**
     * 修改文章标签
     */
    @PreAuthorize("@ss.hasPermi('blog:tags:edit')")
    @Log(title = "文章标签", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogTags blogTags)
    {
        return toAjax(blogTagsService.updateBlogTags(blogTags));
    }

    /**
     * 删除文章标签
     */
    @PreAuthorize("@ss.hasPermi('blog:tags:remove')")
    @Log(title = "文章标签", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tagsIds}")
    public AjaxResult remove(@PathVariable Long[] tagsIds)
    {
        return toAjax(blogTagsService.deleteBlogTagsByTagsIds(tagsIds));
    }
}
